using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_Shop_TryApplication : Member, IRequiresSessionState
{
	protected DropDownList DropProduct;
	protected DropDownList DropStatus;
	protected TextBox NicknameBox;
	protected Button butSearch;
	protected Repeater Repeater1;
	protected Button ButThrough;
	protected Button ButNotThrough;
	protected Label lbPage;
	protected int ProductID = 0;
	public int AppTotalCount = 0;
	public int IsThroughNum = 0;
	public int SurplusNum = 0;
	public int TotalProductNum = 0;
	public int IsConsignmentNum = 0;
	public int SurplusProductNum = 0;
	protected string StrWhere = "";
	protected string StrThrough = "";
	protected string StrName = "";
	protected string StrDate = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (base.Request.QueryString["Through"] != null)
			{
				if (base.Request.QueryString["Through"] != "")
				{
					try
					{
						this.StrWhere = this.StrWhere + " and Through=" + int.Parse(base.Request.QueryString["Through"]);
					}
					catch
					{
						this.StrWhere = "";
					}
					this.StrThrough = "&Through=" + base.Request.QueryString["Through"];
				}
			}
			if (base.Request.QueryString["UserName"] != null)
			{
				if (base.Request.QueryString["UserName"] != "")
				{
					this.StrWhere = this.StrWhere + " and UserName like '%" + base.Request.QueryString["UserName"] + "%' ";
					this.StrName = "&UserName=" + base.Request.QueryString["UserName"];
				}
			}
			if (base.Request.QueryString["Date1"] != null && base.Request.QueryString["Date2"] != null)
			{
				if (base.Request.QueryString["Date1"] != "" && base.Request.QueryString["Date2"] != "")
				{
					string strWhere = this.StrWhere;
					this.StrWhere = string.Concat(new string[]
					{
						strWhere,
						" and CreateTime>='",
						base.Request.QueryString["Date1"],
						"' and CreateTime<='",
						base.Request.QueryString["Date2"],
						"' "
					});
					this.StrDate = "&Date1=" + base.Request.QueryString["Date1"] + "&Date2=" + base.Request.QueryString["Date2"];
				}
			}
			this.GetAllTryProduct();
			if (base.Request.QueryString["ProductID"] != null)
			{
				try
				{
					this.DropProduct.SelectedValue = base.Request.QueryString["ProductID"];
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[]
					{
						"正常操作"
					});
					this.DropProduct.SelectedIndex = 0;
				}
			}
			this.ProductID = int.Parse(this.DropProduct.SelectedValue);
			this.BindApplication();
			this.Count();
		}
	}
	public void BindApplication()
	{
		CurrPageLinks currPageLinks = new CurrPageLinks();
		int num = 1;
		if (base.Request.QueryString["pageindex"] != null)
		{
			if (base.Request.QueryString["pageindex"].ToString() != "")
			{
				try
				{
					num = int.Parse(base.Request.QueryString["pageindex"].ToString());
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[]
					{
						"正常操作"
					});
					num = 1;
				}
			}
		}
		this.AppTotalCount = this.conn.ExecuteCount("select count(*) from HLShop_TryAppcation where ProductID=" + this.ProductID);
		int num2 = (num - 1) * 16;
		DataTable dataTable = this.conn.GetDataTable(string.Concat(new object[]
		{
			"select top 16 * from HLShop_TryAppcation where ApplicationID not in(select top ",
			num2,
			" ApplicationID from HLShop_TryAppcation where ProductID=",
			this.ProductID,
			this.StrWhere,
			" order by CreateTime Desc) and ProductID=",
			this.ProductID,
			this.StrWhere,
			" order by CreateTime Desc"
		}));
		this.Repeater1.DataSource = dataTable;
		this.Repeater1.DataBind();
		dataTable.Dispose();
		this.lbPage.Text = currPageLinks.CurrPageLink(num, 16, this.AppTotalCount, "个商品", string.Concat(new object[]
		{
			"Shop_TryApplication.aspx?ProductID=",
			this.ProductID,
			this.StrThrough,
			this.StrName,
			this.StrDate,
			"&pageindex"
		}));
		for (int i = 0; i < this.Repeater1.Items.Count; i++)
		{
			LinkButton linkButton = (LinkButton)this.Repeater1.Items[i].FindControl("lbtThrough");
			LinkButton linkButton2 = (LinkButton)this.Repeater1.Items[i].FindControl("lbtDeliver");
			if (linkButton.Text == "已审核")
			{
				linkButton.Enabled = false;
			}
			if (linkButton2.Text == "已发货" || linkButton2.Text == "已签收")
			{
				linkButton2.Enabled = false;
			}
		}
	}
	public void GetAllTryProduct()
	{
		DataTable dataTable = this.conn.GetDataTable("select * from HLShop_TryProduct where SalerID=" + base.user.UserID);
		this.DropProduct.DataTextField = "ProductName";
		this.DropProduct.DataValueField = "TryID";
		this.DropProduct.DataSource = dataTable;
		this.DropProduct.DataBind();
		dataTable.Dispose();
		this.DropProduct.SelectedValue = this.ProductID.ToString();
	}
	public string GetAddress(int AddressID)
	{
		string result = "";
		DataTable dataTable = this.conn.GetDataTable("select Address from HLShop_Address where AddressID=" + AddressID);
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			result = dataTable.Rows[0]["Address"].ToString();
		}
		dataTable.Dispose();
		return result;
	}
	public void Count()
	{
		DataTable dataTable = this.conn.GetDataTable("select ProductNum from HLShop_TryProduct where TryID=" + this.ProductID);
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			this.TotalProductNum = int.Parse(dataTable.Rows[0]["ProductNum"].ToString());
		}
		dataTable.Dispose();
		DataTable dataTable2 = this.conn.GetDataTable("select * from HLShop_TryAppcation where ProductID=" + this.ProductID);
		this.IsThroughNum = dataTable2.Select(" Through<>0").Length;
		this.SurplusNum = this.AppTotalCount - this.IsThroughNum;
		this.IsConsignmentNum = dataTable2.Select(" DeliverStatus=1").Length;
		this.SurplusProductNum = this.TotalProductNum - this.IsConsignmentNum;
		dataTable2.Dispose();
	}
	public string SubString(string str)
	{
		string result = str;
		if (str.Length > 27)
		{
			result = str.Substring(0, 25) + "......";
		}
		return result;
	}
	public string GetTruename(string AddressID)
	{
		string result = "";
		DataTable dataTable = this.conn.GetDataTable("select UserName from HLShop_Address where AddressID=" + int.Parse(AddressID));
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			result = dataTable.Rows[0]["UserName"].ToString();
		}
		dataTable.Dispose();
		return result;
	}
	public string GetPhone(string AddressID)
	{
		string result = "";
		DataTable dataTable = this.conn.GetDataTable("select MobilePhone,ConectPhone from HLShop_Address where AddressID=" + int.Parse(AddressID));
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			if (dataTable.Rows[0]["MobilePhone"].ToString() != "")
			{
				result = dataTable.Rows[0]["MobilePhone"].ToString();
			}
			else
			{
				result = dataTable.Rows[0]["ConectPhone"].ToString();
			}
		}
		dataTable.Dispose();
		return result;
	}
	public string GetThroughStatus(string Through)
	{
		int num = 0;
		string result = "未审核";
		if (Through != null && Through != "")
		{
			num = int.Parse(Through);
		}
		if (num == 1)
		{
			result = "已审核";
		}
		else
		{
			if (num == -1)
			{
				result = "已被拒绝";
			}
		}
		return result;
	}
	public string GetDeliverStatus(string DeliverStatus)
	{
		int num = 0;
		string result = "未发货";
		if (DeliverStatus != null && DeliverStatus != "")
		{
			num = int.Parse(DeliverStatus);
		}
		if (num == 1)
		{
			result = "已发货";
		}
		else
		{
			if (num == 2)
			{
				result = "已签收";
			}
		}
		return result;
	}
	protected void lbtThrough_Click(object sender, EventArgs e)
	{
		int num = 0;
		LinkButton linkButton = sender as LinkButton;
		RepeaterItem repeaterItem = linkButton.Parent as RepeaterItem;
		HiddenField hiddenField = repeaterItem.FindControl("HiddenID") as HiddenField;
		try
		{
			num = this.conn.Execute("update HLShop_TryAppcation set Through=1 where ApplicationID=" + int.Parse(hiddenField.Value));
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[0]);
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('审核失败,请联系管理员!');</script>");
		}
		if (num == 1)
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('审核成功!');</script>");
			this.ProductID = int.Parse(this.DropProduct.SelectedValue);
			this.BindApplication();
			this.Count();
		}
	}
	protected void lbtDeliver_Click(object sender, EventArgs e)
	{
		int num = 0;
		this.ProductID = int.Parse(this.DropProduct.SelectedValue);
		LinkButton linkButton = sender as LinkButton;
		RepeaterItem repeaterItem = linkButton.Parent as RepeaterItem;
		HiddenField hiddenField = repeaterItem.FindControl("HiddenID") as HiddenField;
		try
		{
			num = this.conn.Execute("update HLShop_TryAppcation set DeliverStatus=1 where ApplicationID=" + int.Parse(hiddenField.Value));
		}
		catch (Exception ex)
		{
			ex.WriteErrorLog(new string[0]);
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('发货失败,请联系管理员!');</script>");
		}
		if (num == 1)
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('发货成功!');</script>");
			this.ProductID = int.Parse(this.DropProduct.SelectedValue);
			this.BindApplication();
			this.Count();
		}
	}
	protected void ButThrough_Click(object sender, EventArgs e)
	{
		int num = 0;
		int num2 = 0;
		for (int i = 0; i < this.Repeater1.Items.Count; i++)
		{
			CheckBox checkBox = (CheckBox)this.Repeater1.Items[i].FindControl("CheckBox1");
			HiddenField hiddenField = (HiddenField)this.Repeater1.Items[i].FindControl("HiddenID");
			if (checkBox.Checked)
			{
				try
				{
					int num3 = this.conn.Execute("update HLShop_TryAppcation set Through=1 where ApplicationID=" + int.Parse(hiddenField.Value));
					if (num3 == 1)
					{
						num++;
					}
					num2++;
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[0]);
					break;
				}
			}
		}
		if (num == num2 && num != 0)
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('审核成功!');</script>");
			this.ProductID = int.Parse(this.DropProduct.SelectedValue);
			this.BindApplication();
			this.Count();
		}
		else
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('审核失败，请联系管理员!');</script>");
		}
	}
	protected void ButNotThrough_Click(object sender, EventArgs e)
	{
		int num = 0;
		int num2 = 0;
		for (int i = 0; i < this.Repeater1.Items.Count; i++)
		{
			CheckBox checkBox = (CheckBox)this.Repeater1.Items[i].FindControl("CheckBox1");
			HiddenField hiddenField = (HiddenField)this.Repeater1.Items[i].FindControl("HiddenID");
			if (checkBox.Checked)
			{
				try
				{
					int num3 = this.conn.Execute("update HLShop_TryAppcation set Through=-1 where ApplicationID=" + int.Parse(hiddenField.Value));
					if (num3 == 1)
					{
						num++;
					}
					num2++;
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[0]);
					break;
				}
			}
		}
		if (num == num2 && num != 0)
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('已成功决绝!');</script>");
			this.ProductID = int.Parse(this.DropProduct.SelectedValue);
			this.BindApplication();
			this.Count();
		}
		else
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('无法决绝,请联系管理员!');</script>");
		}
	}
	protected void DropProduct_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.ProductID = int.Parse(this.DropProduct.SelectedValue);
		this.GetAllTryProduct();
		this.BindApplication();
		this.Count();
	}
	protected void butSearch_Click(object sender, EventArgs e)
	{
		this.ProductID = int.Parse(this.DropProduct.SelectedValue);
		string selectedValue = this.DropStatus.SelectedValue;
		if (selectedValue != null)
		{
			if (!(selectedValue == "1"))
			{
				if (!(selectedValue == "2"))
				{
					if (selectedValue == "3")
					{
						this.StrWhere = " and Through=-1 ";
						this.StrThrough = "&Through=-1";
					}
				}
				else
				{
					this.StrWhere = " and Through=1 ";
					this.StrThrough = "&Through=1";
				}
			}
			else
			{
				this.StrWhere = " and Through=0 ";
				this.StrThrough = "&Through=0";
			}
		}
		if (this.NicknameBox.Text != "")
		{
			this.StrWhere = this.StrWhere + " and UserName like '%" + this.NicknameBox.Text + "%' ";
			this.StrName = "&UserName=" + this.NicknameBox.Text;
		}
		if (base.Request.Form["BeginDate"] != "" && base.Request.Form["EndDate"] != "")
		{
			string strWhere = this.StrWhere;
			this.StrWhere = string.Concat(new string[]
			{
				strWhere,
				" and CreateTime>='",
				base.Request.Form["BeginDate"],
				"' and CreateTime<='",
				base.Request.Form["EndDate"],
				"' "
			});
			this.StrDate = "&Date1=" + base.Request.Form["BeginDate"] + "&Date2=" + base.Request.Form["EndDate"];
		}
		this.BindApplication();
		this.Count();
	}
}
